my $prefix = "CEU-1409-X-nogeno";
my $mapped_bed_file = $prefix.".mapped.bed";
my $file = "CEU-1409-X-nogeno.vcf";
my $out_vcf_file = $prefix.".hg18.vcf";

open(FH,"</Users/yaping/Documents/workspace/data/dbSNP/VCF/$file") or die;
my @in=<FH>;
chomp(@in);
close(FH);
my @out;
my @out_bed;
my $count_total=0;
my $count_convert=0;
my %hash_snp=();
foreach my $line(@in){
	if($line=~/^\#/){
		push(@out,"$line\n");
	}
	else{
		my @splitin = split "\t",$line;
		my $chr="chr".$splitin[0];
		my $start = $splitin[1];
		my $end = $splitin[1] + 1;
		push(@out_bed,"$chr\t$start\t$end\t$splitin[2]\n");
		$hash_snp{$splitin[2]}=$line;
		$count_total++;
		#print("$splitin[2]\n");
	}
	
}

open(FH,"</Users/yaping/Documents/workspace/data/dbSNP/VCF/$mapped_bed_file") or die;
my @in_new=<FH>;
chomp(@in_new);
close(FH);
foreach my $line(@in_new){
	my @splitin = split "\t",$line;
	my $input_line=$hash_snp{$splitin[3]};
	#my @split_inline=split "\t",$input_line;
	#print("$split_inline[0]\t$split_inline[2]\t$split_inline[3]\t$split_inline[4]\t$split_inline[5]\t$split_inline[6]\t$split_inline[7]\n");
	if($input_line ne NULL){
		my @split_inline=split "\t",$input_line;
		push(@out,"$split_inline[0]\t$splitin[1]\t$split_inline[2]\t$split_inline[3]\t$split_inline[4]\t$split_inline[5]\t$split_inline[6]\t$split_inline[7]\n");
		$count_convert++;
		#print("ok\n");
	}
}
print "$file count_total is : $count_total\ncount_convert is: $count_convert\n";
open(OUT,">/Users/yaping/Documents/workspace/data/dbSNP/VCF/$out_vcf_file");
print OUT @out;
close(OUT);